//
//  NEDRequest+Config.m
//  NEDNetwork
//
//  Created by 000 on 2021/12/26.
//

#import "NEDRequest+Config.h"

@implementation NEDRequest (Config)

- (NEDRequest<id> *(^)(Class responseClass))responseClassRegister{
    NEDRequest *(^block)(Class responseClass) = ^NEDRequest *(Class responseClass) {
        self.config.responseClass = responseClass;
        return self;
    };
    return block;
}

- (NEDRequest<id> *)configure:(void(^)(NEDRequest * request, NEDRequestConfig * config))configBlock{
    if(configBlock){
        configBlock(self,self.config);
    }
    return self;
}

- (NEDRequest<id> *(^)(YTKRequestMethod method))method{
    NEDRequest *(^block)(YTKRequestMethod method) = ^NEDRequest *(YTKRequestMethod method) {
        self.config.method = method;
        return self;
    };
    return block;
}

- (NEDRequest<id> *)GET{
    self.config.method = YTKRequestMethodGET;
    return self;
}
- (NEDRequest<id> *)POST{
    self.config.method = YTKRequestMethodPOST;
    return self;
}
- (NEDRequest<id> *)PUT{
    self.config.method = YTKRequestMethodPUT;
    return self;
}
- (NEDRequest<id> *)DELETE{
    self.config.method = YTKRequestMethodDELETE;
    return self;
}

/// 请求失败重试次数
- (NEDRequest<id> *(^)(NSInteger retryTimes))retryTimes{
    NEDRequest *(^block)(NSInteger retryTimes) = ^NEDRequest *(NSInteger retryTimes) {
        self.config.retryTimes = MAX(0, retryTimes);
        return self;
    };
    return block;
}
- (NEDRequest<id> *(^)(NSInteger retryTimeInterval))retryTimeInterval{
    NEDRequest *(^block)(NSInteger retryTimeInterval) = ^NEDRequest *(NSInteger retryTimeInterval) {
        self.config.retryDelayInterval = MAX(0, retryTimeInterval);
        return self;
    };
    return block;
}

- (NEDRequest<id> *(^)(NSString * pathurl))pathurl{
    NEDRequest *(^block)(NSString * pathurl) = ^NEDRequest *(NSString * pathurl) {
        self.config.pathURL = pathurl;
        return self;
    };
    return block;
}
- (NEDRequest<id> *(^)(NSString * baseurl))baseurl{
    NEDRequest *(^block)(NSString * baseurl) = ^NEDRequest *(NSString * baseurl) {
        self.config.baseURL = baseurl;
        return self;
    };
    return block;
}
- (NEDRequest<id> *(^)(NSString * fullurl))fullurl{
    NEDRequest *(^block)(NSString * fullurl) = ^NEDRequest *(NSString * fullurl) {
        self.config.baseURL = fullurl;
        self.config.pathURL = @"";
        return self;
    };
    return block;
}


/// 参数
- (NEDRequest<id> *(^)(id argument))argument{
    NEDRequest *(^block)(id argument) = ^NEDRequest *(id argument) {
        self.config.argument = argument;
        return self;
    };
    return block;
}

/// 显示加载提示
- (NEDRequest<id> *)HUDLoad{
    self.config.showLoading = YES;
    return self;
}

/// 显示错误提示
- (NEDRequest<id> *)HUDFail{
    self.config.showMessageHUDFail = YES;
    return self;
}

/// 显示错误提示
- (NEDRequest<id> *)HUDSuccess{
    self.config.showMessageHUDSuccess = YES;
    return self;
}

/// 打印结果信息
- (NEDRequest<id> *)log{
    self.config.logResultData = YES;
    return self;
}

@end
